package cn.tedu;

import java.sql.*;

public class Demo04 {
    public static void main(String[] args) throws SQLException {
        //1.获取连接对象
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai",
                "root","root");
        System.out.println(conn);
        //2.创建执行SQl语句对象
        Statement s = conn.createStatement();
        //3.执行查询SQL语句
        ResultSet rs = s.executeQuery("select name,sal from emp");
        while (rs.next()) {
            String name = rs.getString("name");
            String sal = rs.getString("sal");
            System.out.println(name + "," + sal);
        }

        //4.关闭资源
        conn.close();
        System.out.println("执行完成");
    }
}
